<template>
	<view class="padb30">
		<cu-custom bgColor="bg-gradual-blue" isBack>
			<block slot="content">我的订单</block>
			<block slot="backText">返回</block>
		</cu-custom>
		<!-- <view class="flrc bg-white ripple" @tap="$win.navto"
		data-url="/pages/stream/createOrder/createOrder">
			<view class="wh30-30 flcc">
				<text class="fa fa-file-text fa-4x"></text>
			</view>
			<view class="flex1">
				<view class="fs14">创建新订单</view>
				<view>创建、审核、排产、交付</view>
			</view>
			<view class="fa fa-angle-right pad3"></view>
		</view> -->
		<view class=" bdbso">
			<view class="cu-form-group">
				<view class="title">单号查询</view>
				<input placeholder="请输入订单编号" name="input" v-model="text"></input>
				<text class='cuIcon-search text-orange' @tap="search()"></text>
			</view>
		</view>
		
		<scroll-view scroll-x class="bg-white nav pos-f bdtso">
			<view class="cu-item ripple" :class="TabCur==index?'text-orange cur':''" @tap="tab(index)" 
			v-for="item,index in label">
				{{item}}
			</view>
		</scroll-view>
		<scroll-view scroll-x class="bg-white nav" style="visibility: hidden;z-index: -99;">
			<view class="cu-item ripple" :class="TabCur==index?'text-orange cur':''" @tap="tab(index)" 
			v-for="item,index in label">
				{{item}}
			</view>
		</scroll-view>
		<view class="mart3">
			<view class="list-style-1">任务列表</view>
		</view>
		<view>
			<view class="bcf round5 shadow1 marlr3 pad2 mart3" v-for="(item,index) in list" :key="index">
				<view class="flrc padtb1 bdbso">
					<view class="flex1">{{item.streamOrder.sn}}</view>
					<view class=" tar padlr3 padtb1 round1 bdso" :style="'background-color: ' + item.status.background + ';color: ' + item.status.color + ';'">
						{{item.status.name}}
					</view>
					<text class="fa fa-angle-right padl3"></text>
				</view>
				<view class="flex-r flex-start c12 padb3">
					<view class="wh30-30 mart3 marr2">
						<image @tap="viewPic($api.getAssetBaseUrl() + item.streamOrder.cover,[$api.getAssetBaseUrl() + item.streamOrder.cover])"  
						:src="$api.getAssetBaseUrl() + item.streamOrder.cover" class="wh30-30" mode="aspectFill"></image>
					</view>
					<view class="flex1 lh2 fs8 tar">
						<view class="flex1 c11 lh2 fs14 fwb">{{item.streamOrder.info}}</view>
						<view>订单创建：{{$com.str2time(item.streamOrder.createAt)}}</view>
						<view>订单开工：{{$com.str2time(item.streamOrder.startAt)}}</view>
						<view>订单完成：{{$com.str2time(item.streamOrder.finishAt)}}</view>
					</view>
				</view>
				<view class="bdtso pad3 flex-c flex-fill">
					<view class="flex1">
						<view class="list-style-2 marb3 c12">订单备注</view>
						<view>{{item.streamOrder.tips}}</view>
					</view>
					<view class="flex1 lh15 fs8 padt2">
						<view class="flrc pad1 bdtda"><text class="flex1 c12">计划开始：</text>{{$com.str2time(item.createAt)}}</view>
						<view class="flrc pad1 bdtda"><text class="flex1 c12">计划完成：</text>{{$com.str2time(item.targetAt)}}</view>
						<view class="flrc pad1 bdtda"><text class="flex1 c12">实际开始：</text>{{$com.str2time(item.startAt)}}</view>
						<view class="flrc pad1 bdtda bdbda"><text class="flex1 c12">实际完成：</text>{{$com.str2time(item.finishAt)}}</view>
					</view>
					<view class="flex-r flex-end">
						<!-- <view class="cu-btn bg-orange sm mart2 marl1" :data-id="item.id" @tap="$win.goto('/pages/stream/orderInfo/orderInfo',$event)">
							安排生产
						</view> -->
						<view class="cu-btn bg-red sm mart2 marl1" v-if="item.status.sort > 1 && item.status.sort <= showFinishSort"
						:data-id="item.id" @tap="$win.goto('/pages/stream/orderRecord/orderRecord',$event)">
							异常上报
						</view>
						<view class="cu-btn line-orange sm mart2 marl1" :data-id="item.streamOrder.id" @tap="$win.goto('/pages/stream/orderInfo/orderInfo',$event)">
							订单详情
						</view>
						<view class="cu-btn bg-orange sm mart2 marl1"  v-if="item.status.sort == showStartSort"
						:data-id="item.id" @tap="startPoint(item.id)">
							确认开始
						</view>
						<view class="cu-btn bg-green sm mart2 marl1"  v-if="item.status.sort == showFinishSort"
						:data-id="item.id" @tap="$win.goto('/pages/stream/orderPointFinsh/orderPointFinsh',$event)">
							确认完成
						</view>
						<view class="cu-btn line-orange sm mart2 marl1"   v-if="item.status.sort > showFinishSort"
						:data-id="item.id" @tap="$win.goto('/pages/stream/orderPointInfo/orderPointInfo',$event)">
							任务信息
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../../static/js/api.js'
	import com from '../../../static/js/com.js'
	import win from '../../../static/js/win.js'
	import list from '../../../static/js/list.js'
	export default {

		data() {
			return {
				showStartSort:2,
				showFinishSort:3,
				list: [],
				label: ["昨天","今天","明天","后天"],
				start:"",
				end:"",
				text:"",
				TabCur:1,
			}
		},
		methods: {

			tab(index){
				this.TabCur = index
				var data = new Date()
				data.setDate(data.getDate()-1 + index)
				let start = com.getDate(data)
				data.setDate(data.getDate()+1)
				let end = com.getDate(data)
				this.start = start
				this.end = end
				console.log(start)
				console.log(end)
				this.getData()
			},
			getData(){
				list.setData({
					_where:{
						gt:{targetAt:this.start},
						lt:{targetAt:this.end}
					}
				})
				list.reload()
			},

			search() {
				list.setUrl('/api/my/streamOrderPoints')
				list.setData({_search:this.text})
				list.reload()
			},
			startPoint(id) {
				api.post("/api/my/streamOrderPoints/" + id +"/start",{},(res)=>{
					console.log(res)
					com.showToast(res.i)
					list.reload()
				})
			}
		},
		created() {
			this.showStartSort = com.getLocData('PrePointStartStatusSort')
			this.showFinishSort = com.getLocData('PrePointFinishStatusSort')
		},
		onShow() {
			
			let _this = this
			list.setUrl('/api/my/streamOrderPoints')
			list.setData({})
			list.setCbFunc((res) => {
				uni.stopPullDownRefresh();
				console.log(res)
				this.list = res
			})
			list.reload()
			
		},
		onReachBottom() {
			list.getList()
		},
		onPullDownRefresh() {
			list.setData({})
			list.reload()
		}
	}
</script>

<style>

</style>
